package utils;

import android.text.TextUtils;

import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import beans.UserRightsBean;

/**
 * Created by Administrator on 2018/8/14.
 */

public class UserRightSortUtils {

    public static void sortUserRightName (List<UserRightsBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<UserRightsBean>() {
                @Override
                public int compare(UserRightsBean o1, UserRightsBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getName();
                    String name2 = o2.getName();
                    if (TextUtils.isEmpty(o1.getName())) {
                        name1 = "阿阿阿阿";
                    }
                    if (TextUtils.isEmpty(o2.getName())) {
                        name2 = "阿阿阿阿";
                    }
                    if (ca.compare(name2, name1) < 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<UserRightsBean>() {
                @Override
                public int compare(UserRightsBean o1, UserRightsBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getName();
                    String name2 = o2.getName();
                    if (TextUtils.isEmpty(o1.getName())) {
                        name1 = "阿阿阿阿";
                    }
                    if (TextUtils.isEmpty(o2.getName())) {
                        name2 = "阿阿阿阿";
                    }
                    if (ca.compare(name2, name1) > 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    public static void sortUserRightId (List<UserRightsBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<UserRightsBean>() {
                @Override
                public int compare(UserRightsBean o1, UserRightsBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getNumber();
                    String name2 = o2.getNumber();
                    if (TextUtils.isEmpty(o1.getNumber())) {
                        name1 = "阿阿阿阿";
                    }
                    if (TextUtils.isEmpty(o2.getNumber())) {
                        name2 = "阿阿阿阿";
                    }
                    if (ca.compare(name2, name1) > 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<UserRightsBean>() {
                @Override
                public int compare(UserRightsBean o1, UserRightsBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    String name1 = o1.getNumber();
                    String name2 = o2.getNumber();
                    if (TextUtils.isEmpty(o1.getNumber())) {
                        name1 = "阿阿阿阿";
                    }
                    if (TextUtils.isEmpty(o2.getNumber())) {
                        name2 = "阿阿阿阿";
                    }
                    if (ca.compare(name2, name1) < 0) {
                        return 1;
                    } else if (ca.compare(name2, name1) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
}
